<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('借阅信息列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>书本名称：</label>
                                <input type="text" name="bookName"/>
                            </li>
                            <li>
                                <label>用户名称：</label>
                                <input type="text" name="userName"/>
                            </li>
                            <li>
                                <label>图书编号：</label>
                                <input type="text" name="bookNo"/>
                            </li>
                            <li>
                                <label>用户ID：</label>
                                <input type="text" name="userId"/>
                            </li>
                            <li>
                                借出状态：<select name="loanStatus">
                                <option value="">所有</option>
                                <option value="1">正常借阅</option>
                                <option value="2">逾期未归还</option>
                                <option value="3">正常归还</option>
                                <option value="4">逾期已归还</option>
                            </select>
                            </li>
                            <li>
                                <label>借出时间：</label>
                                <input type="text" class="time-input" placeholder="请选择借出时间" name="loanTime"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="restore()" shiro:hasPermission="admin:loan:edit">
                    <i class="fa fa-plus"></i> 还原
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="admin:loan:remove">
                    <i class="fa fa-remove"></i> 永久删除
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('admin:loan:edit')}]];
        var removeFlag = [[${@permission.hasPermi('admin:loan:remove')}]];
        var prefix = ctx + "admin/loan";

        $(function() {
            var options = {
                url: prefix + "/listWithInfoDel",
                removeUrl: prefix + "/removeForever",
                modalName: "借阅信息",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'loanId',
                    title: '${comment}',
                    visible: false
                },
                {
                    field: 'libBook.bookNo',
                    title: '图书编号',
                    visible: false
                },
                {
                    field: 'libBook.name',
                    title: '书本名称',
                },
                {
                    field: 'sysUser.userName',
                    title: '用户名称'
                },
                {
                    field: 'loanTime',
                    title: '借出时间'
                },
                {
                    field: 'preReturnTime',
                    title: '预计归还时间'
                },
                {
                    field: 'praReturnTime',
                    title: '实际归还时间'
                },
                {
                    field: 'loanStatus',
                    title: '借出状态',
                    formatter: function (value, row, index) {
                        if (row.loanStatus == 1) {
                            return '<strong>正常借阅</strong>';
                        } else if (row.loanStatus == 2){
                            return '<strong>逾期未归还</strong>';
                        } else if (row.loanStatus == 3){
                            return '<strong>正常归还</strong>';
                        } else if (row.loanStatus == 4){
                            return '<strong>逾期已归还</strong>';
                        }
                    },
                    cellStyle: function(value,row,index){
                        if (row.loanStatus == 1) {
                            return {
                                css:{
                                    'color':'#510080'
                                }
                            };
                        } else if (row.loanStatus == 2){
                            return {
                                css:{
                                    'color':'#ad0404'
                                }
                            };
                        } else if (row.loanStatus == 3){
                            return {
                                css:{
                                    'color':'#008018'
                                }
                            };
                        } else if (row.loanStatus == 4){
                            return {
                                css:{
                                    'color':'#ee9108'
                                }
                            };
                        }
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="recycle(\'' + row.loanId + '\')"><i class="fa fa-edit"></i>还原</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.loanId + '\')"><i class="fa fa-remove"></i>永久删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function recycle(id){
            $.modal.confirm("确认要还原吗?", function() {
                $.ajax({
                    url:prefix + '/batchRestore',
                    type:'post',
                    data:{ids:id},
                    dataType:'json',
                    beforeSend: function () {
                        $.modal.loading("正在处理中，请稍候...");
                        $.modal.disable();
                    },
                    success: function(result) {
                        if (typeof callback == "function") {
                            callback(result);
                        }
                        $.operate.ajaxSuccess(result);
                    }
                });
            });
        }

        function restore() {
            table.set();
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            var ids = rows.join();
            $.modal.confirm("确认要还原选中的" + rows.length + "条数据吗?", function() {
                $.ajax({
                    url:prefix + '/batchRestore',
                    type:'post',
                    data:{ids},
                    dataType:'json',
                    beforeSend: function () {
                        $.modal.loading("正在处理中，请稍候...");
                        $.modal.disable();
                    },
                    success: function(result) {
                        if (typeof callback == "function") {
                            callback(result);
                        }
                        $.operate.ajaxSuccess(result);
                    }
                });
            });

        }

    </script>
</body>
</html>